//========================================================================
//  This software is free: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License Version 3,
//  as published by the Free Software Foundation.
//
//  This software is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public License
//  Version 3 in the file COPYING that came with this distribution.
//  If not, see <http://www.gnu.org/licenses/>.
//========================================================================
/*!
\file    main.cpp
\brief   Simple demo app for the kinect wrapper
\author  Joydeep Biswas, (C) 2011
*/
//========================================================================

#include "stdio.h"
#include "kinect_wrapper.h"

void depthImageCallback(BYTE* img)
{
  printf("Raw Depth Image received.\n");
}

void labeledDepthImageCallback(BYTE* img)
{
  printf("Labeled Depth Image received.\n");
}

void rgbImageCallback(BYTE* img)
{
  printf("RGB Image received.\n");
}

void skeletonCallback(NUI_SKELETON_FRAME* data)
{
  printf("Skeleton data received.\n");
  printf("Skeleton data:\n");
  printf("  FrameNumber:%d\n", data->dwFrameNumber);
  printf("  Timestamp:%d\n", data->liTimeStamp);

  for(int i=0; i<NUI_SKELETON_COUNT; i++){

    NUI_SKELETON_DATA skeleton = data->SkeletonData[i];

    if(skeleton.eTrackingState==NUI_SKELETON_NOT_TRACKED){
        //This is not a valid skeleton struct, so skip it.
        continue;
    }else if(skeleton.eTrackingState==NUI_SKELETON_POSITION_ONLY){
      printf("  Skeleton %d: Position Only\n",i);
    }else if(skeleton.eTrackingState==NUI_SKELETON_TRACKED){
      printf("  Skeleton %d: Full skeleton tracking\n",i);
    }
    printf("    Tracking ID: %d\n",skeleton.dwTrackingID);
    printf("    Position: %f,%f,%f confidence:%f\n",
      skeleton.Position.x,skeleton.Position.y,skeleton.Position.z,skeleton.Position.w);
    printf("    Clipping: %s %s %s %s\n",
      (skeleton.dwQualityFlags|NUI_SKELETON_QUALITY_CLIPPED_RIGHT)?"Right Side Clipped":"",
      (skeleton.dwQualityFlags|NUI_SKELETON_QUALITY_CLIPPED_LEFT)?"Left Side Clipped":"",
      (skeleton.dwQualityFlags|NUI_SKELETON_QUALITY_CLIPPED_TOP)?"Top Clipped":"",
      (skeleton.dwQualityFlags|NUI_SKELETON_QUALITY_CLIPPED_BOTTOM)?"Bottom Clipped":"");

  }
  
}

int main(int argc, char *argv[])
{
  static const bool debug = false;
  printf("\nKinect Wrapper Test App\n\n");

  printf("Connecting to Kinect...\n");
  KinectWrapper kinect;
  int retval = kinect.connect(NULL,&labeledDepthImageCallback,&skeletonCallback,&rgbImageCallback);
  printf(" returned value=%d\n",retval);

  while(true){
    kinect.poll();
    Sleep(0.01);
  }

  return retval;
}
